home *** CD-ROM | disk | FTP | other *** search
- ;void box_left(box,col,row,width,depth);
- ; unsigned char *box,*col,*row,width,depth;
-
- EXTRN _memory_model:byte
- EXTRN _video_buffer:word
- EXTRN _snow_protect:byte
-
- box_seg EQU [bp-2]
- box_ofs EQU [bp-4]
- col_seg EQU [bp-6]
- col_ofs EQU [bp-8]
- row_seg EQU [bp-10]
- row_ofs EQU [bp-12]
- width EQU [bp-14]
- depth EQU [bp-16]
- snow EQU [bp-18]
- endofbox EQU [bp-20]
- toppos EQU [bp-22]
- rghtpos EQU [bp-24]
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _box_left
- _box_left proc near
- push bp ;
- mov bp,sp ;set stack frame
- sub sp,24 ;make room to hold parameters
- pushf ;
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: push ds ;save Turbo's DS
- mov dx,_video_buffer ;grab _video_buffer
- push dx ;save it
- cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- push [bp+6] ;move parameters to SP offsets
- push [bp+10]
- push [bp+14]
- push [bp+4]
- push [bp+8]
- push [bp+12]
- push [bp+16]
- push [bp+18]
- jmp short L00
- L0: push ds ;near case
- push ds
- push ds
- push [bp+4]
- push [bp+6]
- push [bp+8]
- mov al,[bp+10]
- sub ah,ah
- push ax
- mov al,[bp+12]
- push ax
- L00: cmp _memory_model,0 ;check code model again
- jle L000 ;jump if near
- dec bp ;unadjust BP so all BP offsets same
- dec bp ;
- L000: pop depth ;set intermediate values
- pop width
- pop row_ofs
- pop col_ofs
- pop box_ofs
- pop row_seg
- pop col_seg
- pop box_seg
- mov ax,col_seg ;ES:DI pts to Col
- mov es,ax ;
- mov di,col_ofs ;
- mov al,_snow_protect ;grab _snow_protect
- mov snow,al ;save it
- sub cx,cx ;
- mov cl,es:[di] ;get column position
- jcxz J1 ;quit if column is zero
- dec cx ;count from zero
- cmp cx,79 ;in range?
- jna I1 ;jump ahead if so
- jmp T1 ;else quit
- I1: cmp cx,2 ;not on left edge?
- jnb K1 ;jump ahead if not
- J1: jmp T1 ;else quit routine
- K1: dec cx ;old col minus 2
- mov es:[di],cl ;change the setting
- inc cx ;restore old col pos
- mov ax,box_seg ;segment of Box
- mov es,ax ;load in ES
- mov di,box_ofs ;offset of Box
- mov ax,depth ;depth to AX
- dec ax ;dec for test
- cmp ax,24 ;in range?
- jna L1 ;jump ahead if so
- jmp T1 ;else quit routine
- L1: inc ax ;readjust
- mov bx,width ;width to BX
- dec bx ;dec for test
- cmp bx,79 ;in range?
- jna M1 ;jump ahead if so
- jmp T1 ;else quit
- M1: inc bx ;readjust
- mul bl ;width times depth
- shl ax,1 ;double for attributes
- add ax,di ;offset to end of Box
- mov endofbox,ax ;save end of box ptr
- mov di,ax ;pt ES:DI to end of Box
- mov ax,row_seg ;DS:SI pts to Row
- mov ds,ax ;
- mov si,row_ofs ;
- sub ax,ax ;
- mov al,[si] ;get row value
- dec ax ;count from zero
- cmp ax,24 ;in range?
- jna N1 ;jump ahead if so
- jmp T1 ;else quit
- N1: mov bl,160 ;bytes per row
- mul bl ;calculate row offset
- shl cx,1 ;col offset
- add ax,cx ;add to row offset
- mov si,ax ;SI pts to topleft corner
- mov toppos,si ;save it
- mov ax,dx ;_video_buffer
- mov ds,ax ;move to DS
- mov ax,width ;width
- shl ax,1 ;double for attributes
- add si,ax ;DS:SI pts to topright
- mov rghtpos,si ;copy position
- pop bx ;_video_buffer
- cld ;set direction
- mov si,toppos ;point to topleft corner
- sub si,4 ;minus two columns
- mov cx,depth ;depth
- mov dx,si ;DX holds start col
- O1: mov si,dx ;set start col
- call Writeit ;write a char
- call Writeit ;write another
- add dx,160 ;forward one row
- loop O1 ;do next row
- mov ax,ds ;DS to AX
- mov es,ax ;now ES pts to screen too
- mov si,toppos ;top left position
- mov di,si ;copy to DI
- sub di,4 ;will shift right by 2
- mov dx,depth ;depth
- mov ax,width ;width
- P1: mov cx,ax ;width to CX
- push di ;save target start
- push si ;save source start
- Q1: call Writeit ;write a char
- loop Q1 ;go do next
- pop si ;restore source start
- pop di ;restore target start
- add di,160 ;forward dest ptr
- add si,160 ;forward source ptr
- dec dx ;dec row counter
- jnz P1 ;loop till image shifted
- mov ax,box_seg ;segment of Box
- mov ds,ax ;move to DS
- mov si,box_ofs ;offset of Box
- mov di,rghtpos ;ES:DI pts to old topleft
- sub di,4 ;leftwards by 2 cols
- mov cx,depth ;depth
- mov dx,width ;width
- sub dx,2 ;minus 2 for 2 columns
- shl dx,1 ;double for attributes
- R1: add si,dx ;forward Box ptr
- call Writeit ;write a char
- call Writeit ;write another
- add di,156 ;forward target ptr
- loop R1 ;do next row
- std ;reverse direction flag
- mov ax,ds ;DS pts to Box
- mov es,ax ;now ES does too
- mov di,endofbox ;offset to end of Box
- dec di ;dec screen ptr
- dec di ;again
- mov si,di ;copy to SI
- sub si,4 ;source pos 2 chars left
- mov ax,depth ;depth
- mov cx,width ;width
- mul cl ;size of Box
- mov cx,ax ;move to CX as counter
- rep movsw ;shift all downwards
- mov di,box_ofs ;offset of Box
- mov si,endofbox ;offset of Col
- mov cx,depth ;depth
- cld ;direction flag forward
- S1: movsw ;move first word of two
- movsw ;move the next
- add di,dx ;forward target ptr
- loop S1 ;go move 2 more chars
- jmp short U1 ;jump to end
- T1: pop bx ;balance stack if error
- U1: sti ;reenable interrupts
- pop ds ;
- pop si ;
- pop di ;
- popf ;
- add sp,24 ;restore stack pointer
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _box_left endp
- Writeit PROC
- push dx ;save DX
- push ax ;save AX too
- mov dx,es ;get target segment
- mov ax,ds ;get source segment
- cmp ax,dx ;is source larger?
- jna A1 ;jump if not
- mov dx,ax ;else use source
- A1: cmp byte ptr snow,0 ;protect against snow?
- je F1 ;jump ahead if not
- mov dx,3dah ;status byte address
- B1: in al,dx ;get status byte
- test al,1 ;test bit
- jnz B1 ;loop till 0
- cli ;disable interrupts
- C1: in al,dx ;get status byte
- test al,1 ;test bit
- jz C1 ;loop till 1
- movsb ;write a char
- D1: in al,dx ;get status byte
- test al,1 ;test bit
- jnz D1 ;loop till 0
- E1: in al,dx ;get status byte
- test al,1 ;test bit
- jz E1 ;loop till 1
- movsb ;write a char
- jmp short G1 ;jump ahead and quit
- F1: movsw ;move the character
- G1: pop ax ;restore AX
- pop dx ;restore DX
- ret ;
- Writeit endp
- _TEXT ENDS
- END